$(document).ready(function() {
	
	var toid = new Array();
	var tid = new Array();
	
	getCurrent(1,10);
	
	// 分页查询，查第一页
	$("#firstPage").click(function() {
				getCurrent(1,10);
			});
	// 分页查询，查上一页
	$("#prePage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#page").text();
				page = (parseInt(page) - 1);
				if (page <= 0) {
					alert("当前已是第一页！");
					return false;
				}
				getCurrent(page,10);
			});
	// 分页查询，查下一页
	$("#nextPage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#page").text();
				page = (parseInt(page) + 1);
				if (page > pageCount) {
					alert("当前已是末页！");
					return false;
				}
				getCurrent(page,10);
			});
	// 分页查询，查最后一页
	$("#lastPage").click(function() {
				var page = $("#pageCount").text();
				getCurrent(page,10);
			});
	// 分页查询，跳转到第n页
	$("#jumpPage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#jump").val();
				if (page > pageCount) {
					alert("页数越界！");
					//$("#pageCount").text(0);
					return false;
				}
				getCurrent(page,10);
			});

	function getCurrent(page1,maxRow1){
			var page = page1;
			var tid = $.cookie('zhhtaskid');
//			alert("list taskid "+$.cookie('zhhtaskid'));
			$.ajax({
				type : "post",
				url : "hmk/findTaskOr_findTOR.action",
				data : {
					tID:tid,page:page
				},
				success : showData,
				
				error : function(textStatus) {
					$("#loadingTrack").hide();
					$("#noneTrack").show();
					alert("Ajax请求失败，请检查本地的网络连接！");
					return false;
				}
			});
	}

	function showData(data) {
			$("#trackList").empty();
		
		if (data.pageUtil.list.length==0 ) {
			$("#loadingTrack").hide();
			$("#noneTrack").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			
			$("#savetid").text($.cookie('zhhtaskid'));
			$("#savetoid").text("noResult");
			
			setTimeout(window.parent.frames["taskOverFrame"].location.href("/ag/zhh/task_over_or_request.jsp"),1000);

		} else {
			$("#trackList").hide();
			$("#noneTrack").hide();
			$("#loadingTrack").hide();
			$.each(data.pageUtil.list, function(i, n) {         //b办结人，c申请人
				        toid[i] = n.toId;	
				        tid[i] = n.tbTask.TId;
						fillHtml(n.toId,n.tbTask.TId, n.tbTask.TName, n.toTime,n.tbOverStatus.sname,n.c,n.b);
					});
			
			$("#savetid").text(tid[0]);
			$("#savetoid").text(toid[0]);
			
			$("#total").text(data.pageUtil.total);
			$("#page").text(data.pageUtil.page);
			$("#pageCount").text(Math.ceil(data.pageUtil.total / 10));
			$("#trackList").show();
//			var url = "/ag/lzw/TaskOver_overRight.action?taskid="+tid[0]+"&toid="+toid[0];
//		    window.location.href=url;
		}
		
		
	}

	function fillHtml(toid,id, tname,time,status,shenqingren,banjieren) {
		var strHtml = "<tr>";
		strHtml += "<td height='18' bgcolor='#FFFFFF' id='toid'><div align='center' class='STYLE1' id='toidd'>"
			    + toid + "</div></td>";
//		strHtml += "<td height='18' bgcolor='#FFFFFF' id='toReason' style='display: none'>"+toReason+"</td>";
//		strHtml += "<td height='18' bgcolor='#FFFFFF' id='TContext' style='display: none'>"+TContext+"</td>";
		strHtml += "<td height='18' bgcolor='#FFFFFF' id='id'><div align='center' class='STYLE1' id='tid'>"
				+ id + "</div></td>";
		strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ tname + "</div></td>";
		strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ status + "</div></td>";        //办结申请表里的B字段记录的任务状态
		if(shenqingren!=null){
		   strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
			       + shenqingren + "</div></td>";
		   }else{
			   strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				    +"无</div></td>";
		}
		if(banjieren!=null){
			strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				    + banjieren +"</div></td>";     
			}else{
				strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				    +"暂无处理</div></td>";   
			}
		if(time!=null){
		strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
			    + time.replace(/T/," ")+"</div></td>";     
		}else{
			strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
			    +"无</div></td>";   
		}
		strHtml += "<td height='18' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+"<button class='read'>查看</button>"+"</div></td>";
		strHtml += "</tr>";

		$("#trackList").append(strHtml);
		

		/*
		var id_value = "#" + $.trim(time);// 去除id字符串的空格
		$(id_value).click(function() {
			// window.location.href="/ag/wzp/event_findById.action?event.EId="+eid;
			$('#mainFrame', window.parent.document).attr("src",
					"lzw/task_detail_main.jsp");
		});
		*/
	}
	
	setTimeout(t,800);
	function t(){
	$(".read").click(function() { 
		var toid2 = $(this).parent().parent().siblings("#toid").children('#toidd').text();
		var tid2 = $(this).parent().parent().siblings("#id").children('#tid').text();
		$("#savetid").text(tid2);
		$("#savetoid").text(toid2);
		setTimeout(window.parent.frames["taskOverFrame"].location.href("/ag/zhh/task_over_or_request.jsp"),1000);			
	});
	}

	
});

